package com.yanqu.road.server.cmd.player;

import com.yanqu.road.pb.recharge.RechargeProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.logic.recharge.RechargeManager;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Cmd(code = Protocol.S_RECHARGE_SUCCESS, desc = "充值支付成功")
public class RechargeSuccessCmd extends AbstractCommand {

    private static Logger logger = LogManager.getLogger(RechargeSuccessCmd.class.getName());

    private String orderNo;

    private int rechargeType;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        RechargeProto.RechargeSuccessMsg reqMsg = RechargeProto.RechargeSuccessMsg.parseFrom(packet.getBytes());
        orderNo = reqMsg.getOrderNo();
        rechargeType = reqMsg.getRechargeType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
         GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(player.getUserId());
         if(null != onlinePlayer){
             if(0 == rechargeType){
                 RechargeManager.notifyPlayerRechargeSuccess(orderNo);
             }else if(1 == rechargeType){
                 RechargeManager.notifyPlayerThirdPartyRechargeSuccess(orderNo);
             }else if(2 == rechargeType){
                 RechargeManager.notifyGoldTokenRechargeSuccess(orderNo);
             }
         }else{
             logger.warn("充值成功通知，玩家不在线，orderNo:{},userId:{}", orderNo, player.getUserId());
         }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
